﻿using System.Linq.Expressions;

namespace ConsoleApp5
{
    //5 表达式树
    //?待定
    internal class Program
    {
        static void Main(string[] args)
        {
            // 创建参数表达式
            ParameterExpression x = Expression.Parameter(typeof(int), "x");
            ParameterExpression y = Expression.Parameter(typeof(int), "y");

            // 创建表达式树节点
            BinaryExpression add = Expression.Add(x, y);

            // 编译表达式树
            Func<int, int, int> addFunction = Expression.Lambda<Func<int, int, int>>(add, x, y).Compile();

            // 调用编译后的函数
            int result = addFunction(10, 20);
            Console.WriteLine("Result: " + result);
            Console.WriteLine("******************");
            // Addition is an add expression for "1 + 2"
            var one = Expression.Constant(1, typeof(int));
            var two = Expression.Constant(2, typeof(int));
            var addition = Expression.Add(one, two);
            Console.WriteLine(addition);
        }



    }
}